package ejb.facade;


import ejb.dao.InvitationDAO;
import ejb.entities.Event;

import ejb.entities.Invitation;
import ejb.entities.User;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import web.beans.Login;


@Stateless
public class InvitationFacadeImp implements InvitationFacade{
        
        @EJB 
	private InvitationDAO invitationDAO;
	
        @Inject
	private Login login;
        
	@Override
	public void save(Invitation s) {
		// TODO Auto-generated method stub
		invitationDAO.save(s);
	}

	@Override
	public Invitation update(Invitation s) {
		// TODO Auto-generated method stub
		return invitationDAO.update(s);
	}

	@Override
	public void delete(Invitation s) {
		// TODO Auto-generated method stub
		invitationDAO.delete(s);
	}

	@Override
	public Invitation find(int entityID) {
		// TODO Auto-generated method stub
		return invitationDAO.find(entityID);
	}

	@Override
	public List<Invitation> findAll() {
		// TODO Auto-generated method stub
		return invitationDAO.findAll();
	}
        
        @Override
	public List<Invitation> findInvitationByEvent(Event evented){
		return invitationDAO.findInvitationByEvent(evented);
	}
        
        @Override
	public List<Invitation> findInvitationByUser(User user) {
		return invitationDAO.findInvitationByUser(user);
	}
        
        @Override
	public List<Invitation> findInvitationByUserAfterToday(User user) {
                List <Invitation> nextInvitation;
                nextInvitation = new ArrayList();
                Date todayDate = login.getToday();   
                for(Invitation inv : invitationDAO.findInvitationByUser(user)){
                      if(inv.getEvent().getDateTimeStart().after(todayDate)){
                          nextInvitation.add(inv);
                      }                
                }
                return nextInvitation;
	}
        
}
